import {AbstractService} from "./abstractService";
import {apiConfig, httpServer} from "../serverConfig/serverManager";
import {changeLoginState} from "../serverConfig/serverManager";

export class UserService extends AbstractService {
  constructor() {
    super()
  }

  login(username, password) {
    const cmd = apiConfig.user.login;
    const data = {
      username: username,
      password: password
    }
    return httpServer.postData(cmd, data).then((res) => {
      changeLoginState(true)
    })
  }

  register(username, password, email) {
    const cmd = apiConfig.user.register;
    const data = {
      username: username,
      password: password,
      email: email
    }
    return httpServer.postData(cmd, data).then(res => res.data)
  }

  info() {
    const cmd = apiConfig.user.info;
    return httpServer.getData(cmd, null).then(res => res.data)
  }
}
